package com.formiaomiao.demain.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.formiaomiao.demain.activity.MainActivity;
import com.formiaomiao.demain.activity.WelcomeActivity;
import com.formiaomiao.demain.util.ActivityIsVisable;

public class NotificationClickReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //处理点击事件
        //todo 跳转之前要处理的逻辑
        try {
            if(!ActivityIsVisable.isForeground(MainActivity.main)){
                MainActivity.main.finish();
                MainActivity.main=null;
                Intent newIntent = new Intent();
                newIntent.setClass(context, WelcomeActivity.class);
                newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newIntent.putExtra("from","service");
                context.startActivity(newIntent);
            }else{
                if(MainActivity.main==null){
                    Intent newIntent = new Intent();
                    newIntent.setClass(context, MainActivity.class);
                    newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    context.startActivity(newIntent);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
